<?php
namespace app\extra\H5WeixinSDK\V3;

/**
 * 请求型接口的基类
 */
class Wxpayclientpub extends \app\extra\H5WeixinSDK\V3\Commonutilpub {

    var $parameters; //请求参数，类型为关联数组
    public $response; //微信返回的响应
    public $result; //返回参数，类型为关联数组
    var $url; //接口链接
    var $curl_timeout; //curl超时时间

    /**
     * 	作用：设置请求参数
     */

    function setParameter($parameter, $parameterValue) {
        $this->parameters[$this->trimString($parameter)] = $this->trimString($parameterValue);
    }

    /**
     * 	作用：设置标配的请求参数，生成签名，生成接口参数xml
     */
    public function createXmld() {
        $this->parameters["appid"]     = WxPayConfpub::APPID; //公众账号ID
        $this->parameters["mch_id"]    = WxPayConfpub::MCHID; //商户号
        $this->parameters["nonce_str"] = $this->createNoncestr(); //随机字符串
        $this->parameters["sign"]      = $this->getSign($this->parameters); //签名
        return $this->arrayToXml($this->parameters);
    }

    /**
     * 	作用：post请求xml
     */
    public function postXml() {

        $xml = $this->createXml();

        $this->response = $this->postXmlCurl($xml, $this->url, $this->curl_timeout);

        return $this->response;
    }

    /**
     * 	作用：post请求xml
     */
    public function postXmlapp() {
        $xml            = $this->createXmlapp();
        $datareq        = Commonutilpub::xmlToArray($xml);
        $this->response = $this->postXmlCurlapp($xml, $this->url, $this->curl_timeout);
        $datareq2       = Commonutilpub::xmlToArray($this->response);
        $this->response = array_merge($datareq, $datareq2);

        return $this->response;
    }

    /**
     * 	作用：使用证书post请求xml
     */
    public function postXmlSSL() {
        $xml            = $this->createXmlred();
        $this->response = $this->postXmlSSLCurl($xml, WxPayConfpub::SENDREDPACK, $this->curl_timeout);
        return $this->response;
    }

    /**
     * 	作用：获取结果，默认不使用证书
     */
    public function getResult() {
        $this->postXml();
        $this->result = $this->xmlToArray($this->response);
        return $this->result;
    }

}

?>
